

def pre_menus(menus_data):
    menus = []
    if len(menus_data) > 0:
        for i in menus_data:
            if i['parent_id'] == 0:
                menus.append(i)

        for idx, item in enumerate(menus):
            child = []
            for j in menus_data:
                if j['parent_id'] == item['id']:
                    child.append(j)
            item['children'] = child
            menus[idx] = item
    return menus